package com.rfsp.mcp.service;

import com.rfsp.common.util.BeanUtil;
import com.rfsp.mcp.mapper.SystemCodeMapper;
import com.rfsp.mcp.pojo.dto.SmsDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rfsp.common.base.BaseService;
import com.rfsp.mcp.pojo.po.SmsPO;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class SmsLoopService extends BaseService<SmsPO> {

	public Logger log = LoggerFactory.getLogger(SmsLoopService.class);
	@Autowired
	private SystemCodeMapper systemCodeMapper;

	public Integer create(SmsDTO dto){
		SmsPO po=new SmsPO();
		BeanUtil.copyProperties(dto,po);

		Map<String, String> map = new HashMap<String, String>();
		map.put("sequenceName", "SEQ_SMSTASK_LOOP");
		String seqence = "" + systemCodeMapper.getSequence(map).getSequenceNo();

		String num = "";
		if (seqence.length() < 7) {
			for (int i = 0; i < 7 - seqence.length(); i++) {
				num += "0";
			}
		}
		String serial_number = "9" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + num + seqence;
		dto.setSerialNumber(serial_number);
		po.setId(Long.parseLong(seqence));
		po.setSerialNumber(serial_number);

		//按说应该是2，但是现在写成3的原因是
		//36894 【仿灾备】两定机构-申请融资-提交成功发送短信给资金方-20点后短信变成定时了？
		po.setSmsType("3"); //1,定时；2，实时；3，紧急；
		po.setSendDate(new Date());
		po.setSendNum(Short.parseShort("0"));
		po.setTaskStatus("1");
		po.setRemark("");
		po.setCreateTime(new Date());

		return  mapper.insertSelective(po);
	}
}
